<template>
	<view class="boxflx">
		<view class="boxList">
				<qiun-data-charts class="charts" type="area" :opts="opts" :chartData="chartData" :ontouch="true" />
		</view>

	</view>
</template>

<script>
	import dayjs from '@/common/dayjs.min.js';
	export default {
		props: {
			listobjSSW: {
				type: Object,
				default: () => {
					return {}
				}
			},
		},
		data() {
			return {
				chartData: {},
				//这里的 opts 是图表类型 type="area" 的全部配置参数，您可以将此配置复制到 config-ucharts.js 文件中下标为 ['area'] 的节点中来覆盖全局默认参数。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					timing: "easeOut",
					duration: 1000,
					rotate: false,
					rotateLock: false,
					color: ["#f58284", "#1890FF", "#91CB74"],
					padding: [15, 15, 0, 15],
					fontSize: 13,
					fontColor: "#666666",
					dataLabel: true,
					dataPointShape: true,
					dataPointShapeType: "solid",
					touchMoveLimit: 60,
					enableScroll: true,
					enableMarkLine: false,
					legend: {
						show: true,
						position: "bottom",
						float: "center",
						padding: 5,
						margin: 5,
						backgroundColor: "rgba(0,0,0,0)",
						borderColor: "rgba(0,0,0,0)",
						borderWidth: 0,
						fontSize: 13,
						fontColor: "#666666",
						lineHeight: 11,
						hiddenColor: "#CECECE",
						itemGap: 10
					},
					xAxis: {
						disableGrid: true,
						disabled: false,
						axisLine: true,
						axisLineColor: "#CCCCCC",
						calibration: false,
						fontColor: "#666666",
						fontSize: 13,
						lineHeight: 20,
						marginTop: 0,
						rotateLabel: false,
						rotateAngle: 45,
						itemCount: 5,
						boundaryGap: "center",
						splitNumber: 5,
						gridColor: "#CCCCCC",
						gridType: "solid",
						dashLength: 4,
						gridEval: 1,
						scrollShow: false,
						scrollAlign: "left",
						scrollColor: "#A6A6A6",
						scrollBackgroundColor: "#EFEBEF",
						title: "",
						titleFontSize: 13,
						titleOffsetY: 0,
						titleOffsetX: 0,
						titleFontColor: "#666666",
						format: ""
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2,
						disabled: false,
						disableGrid: false,
						splitNumber: 5,
						gridColor: "#CCCCCC",
						padding: 10,
						showTitle: false,
						data: []
					},
					extra: {
						area: {
							type: "curve",
							opacity: 0.2, //****
							addLine: true,
							width: 2,
							gradient: true, //yanse
							activeType: "hollow"
						},
						tooltip: {
							showBox: true,
							showArrow: true,
							showCategory: false,
							borderWidth: 0,
							borderRadius: 0,
							borderColor: "#000000",
							borderOpacity: 0.7,
							bgColor: "#000000",
							bgOpacity: 0.7,
							gridType: "solid",
							dashLength: 4,
							gridColor: "#CCCCCC",
							boxPadding: 3,
							fontSize: 13,
							lineHeight: 20,
							fontColor: "#FFFFFF",
							legendShow: true,
							legendShape: "circle",
							splitLine: true,
							horizentalLine: false,
							xAxisLabel: false,
							yAxisLabel: false,
							labelBgColor: "#FFFFFF",
							labelBgOpacity: 0.7,
							labelFontColor: "#666666"
						},
						markLine: {
							type: "solid",
							dashLength: 4,
							data: []
						}
					},
					times13: '',
					times12: '',
					times11: '',
					times10: '',
					times9: '',
					times8: '',
					times7: '',
					times6: '',
					times5: '',
					times4: '',
					times3: '',
					times2: '',
					times1: '',
				}
			};
		},
		onLoad() {

		},
		methods: {
			onloshow() {
				this.chartData = {}
				this.getServerData();
				let now = dayjs();
				// 当前时间减去2小时
				this.times13 = now.subtract(0, 'hour').format('HH') + ":" + "00"
				this.times12 = now.subtract(2, 'hour').format('HH') + ":" + "00"
				this.times11 = now.subtract(4, 'hour').format('HH') + ":" + "00"
				this.times10 = now.subtract(6, 'hour').format('HH') + ":" + "00"
				this.times9 = now.subtract(8, 'hour').format('HH') + ":" + "00"
				this.times8 = now.subtract(10, 'hour').format('HH') + ":" + "00"
				this.times7 = now.subtract(12, 'hour').format('HH') + ":" + "00"
				this.times6 = now.subtract(14, 'hour').format('HH') + ":" + "00"
				this.times5 = now.subtract(16, 'hour').format('HH') + ":" + "00"
				this.times4 = now.subtract(18, 'hour').format('HH') + ":" + "00"
				this.times3 = now.subtract(20, 'hour').format('HH') + ":" + "00"
				this.times2 = now.subtract(22, 'hour').format('HH') + ":" + "00"
				this.times1 = now.subtract(24, 'hour').format('HH') + ":" + "00"
			},
			getServerData() {
				console.log('this.listobjSSW', this.listobjSSW);
				let sswarr = this.listobjSSW
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						categories: [],
						series: [{
								name: "上限水位",
								data: []
							}, {
								name: "实时水位",
								data: []
							},
							{
								name: "下限水位",
								data: []
							},
						]
					};

					if(!(uni.$u.test.isEmpty(sswarr.hlut))){
						if (sswarr.hlut.typ == '今天') {
							res.categories = sswarr.hlut.time.map((i) => {
								return dayjs(i).format('HH:mm')
							})
							res.series[0].data = sswarr.hlut.data
							res.series[1].data = sswarr.watl.data
							res.series[2].data = sswarr.hldt.data
							this.chartData = res
						} else {
							res.categories = sswarr.hlut.time.map((i) => {
								return dayjs(i).format('MM-DD')
							})
							res.series[0].data = sswarr.hlut.data
							res.series[1].data = sswarr.watl.data
							res.series[2].data = sswarr.hldt.data
							this.chartData = res
						}
					}
				}, 300);
			},
		}
	};
</script>

<style scoped lang="scss">
	.boxflx {
		padding: 30rpx;

		.boxList {
			width: 100%;
			height: 520rpx;
			padding-top: 20rpx;
			border-radius: 20rpx;
			background-color: #ffffff;

		}
	}
</style>
<style>
	page {
		background-color: #d4dcdd;
	}
</style>